package com.zqxq.lottery.entity.o2o.user;

import com.zqxq.common.utils.BigDecimalUtils;
import com.zqxq.common.utils.DispatcherUtils;
import com.zqxq.lottery.entity.po.user.UserPrizePO;
import com.zqxq.lottery.entity.vo.user.UserPrizeVO;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/03/14 16:16
 */
public class UserPrizeO2O {

    public static UserPrizeVO toVO(UserPrizePO po) {
        if (po == null) {
            return null;
        }
        UserPrizeVO userPrizeVO = new UserPrizeVO();
        userPrizeVO.setId(DispatcherUtils.parseString(po.getId()));
        userPrizeVO.setUserId(DispatcherUtils.parseString(po.getUser_id()));
        userPrizeVO.setOrderId(DispatcherUtils.parseString(po.getOrder_id()));
        userPrizeVO.setLotteryId(DispatcherUtils.parseString(po.getLottery_id()));
        userPrizeVO.setPeriod(po.getPeriod());
        userPrizeVO.setLotteryNum(po.getLottery_num());
        BigDecimal prizeDecimal = BigDecimalUtils.getValue(po.getPrize(),2) ;
        String prize = prizeDecimal == null ? null : prizeDecimal.toPlainString();
        userPrizeVO.setPrize(prize);
        BigDecimal afterTaxDecimal = BigDecimalUtils.getValue(po.getAfter_tax(),2) ;
        String afterTax = afterTaxDecimal == null ? null : afterTaxDecimal.toPlainString();
        userPrizeVO.setAfterTax(afterTax);
        userPrizeVO.setRecWay(DispatcherUtils.parseString(po.getRec_way()));
        userPrizeVO.setRecStatus(DispatcherUtils.parseString(po.getRec_status()));
        userPrizeVO.setCreateTime(DispatcherUtils.parseDateTimeStr(po.getCreate_time()));
        userPrizeVO.setUpdateTime(DispatcherUtils.parseDateTimeStr(po.getUpdate_time()));
        return userPrizeVO;
    }

    public static UserPrizePO toPO(UserPrizeVO vo) {
        if (vo == null) {
            return null;
        }
        UserPrizePO userPrizePO = new UserPrizePO();
        userPrizePO.setId(DispatcherUtils.parseLong(vo.getId()));
        userPrizePO.setUser_id(DispatcherUtils.parseLong(vo.getUserId()));
        userPrizePO.setOrder_id(DispatcherUtils.parseLong(vo.getOrderId()));
        userPrizePO.setLottery_id(DispatcherUtils.parseLong(vo.getLotteryId()));
        userPrizePO.setPeriod(vo.getPeriod());
        userPrizePO.setLottery_num(vo.getLotteryNum());
        userPrizePO.setPrize(BigDecimalUtils.getBigDecimal(vo.getPrize()));
        userPrizePO.setAfter_tax(BigDecimalUtils.getBigDecimal(vo.getAfterTax()));
        userPrizePO.setRec_way(DispatcherUtils.parseInteger(vo.getRecWay()));
        userPrizePO.setRec_status(DispatcherUtils.parseInteger(vo.getRecStatus()));
        userPrizePO.setCreate_time(DispatcherUtils.parseDateTime(vo.getCreateTime()));
        userPrizePO.setUpdate_time(DispatcherUtils.parseDateTime(vo.getUpdateTime()));
        return userPrizePO;
    }

    public static List<UserPrizeVO> toVOList(List<UserPrizePO> list){
        List<UserPrizeVO> result = new ArrayList();
        if(list != null && list.size() > 0){
            for (UserPrizePO po : list) {
                result.add(toVO(po));
            }
        }
        return result;
    }


}
